package com.ctshk.rpc.order.scenic.service.app;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class ScenicOrderUtilService {
    /**
     * 生成收款单号:
     * SKD+年後2位+月日4位+時分秒6位+2位隨機數字
     */
    public static String generatorPaymentNumber(LocalDateTime nowLocalDateTime) {
        String date = nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        String time = nowLocalDateTime.format(DateTimeFormatter.ofPattern("HHmmss"));
        String randomNumber = String.valueOf((int) ((Math.random() * 9 + 1) * 10));
        StringBuilder orderNumberSb = new StringBuilder();
        orderNumberSb.append("SKD").append(date).append(time).append(randomNumber);
        return orderNumberSb.toString().toUpperCase();
    }

    /**
     * 生成收據號碼：門市編號+員工編號+年後2位月日4位+B+時分秒6位+（S），
     * 例如：XS-C07884-200407-B-110008（S）
     * @return
     */
    public static String generatorReceiptNumber(LocalDateTime nowLocalDateTime) {
        String symbol = "-";
        String date = nowLocalDateTime.format(DateTimeFormatter.ofPattern("yyMMdd"));
        String time = nowLocalDateTime.format(DateTimeFormatter.ofPattern("HHmmss"));
        StringBuilder receiptNumberSb = new StringBuilder();
        receiptNumberSb.append("XS").append(symbol).append(symbol)
                .append(date).append("-B-")
                .append(time).append("（S）");
        return receiptNumberSb.toString().toUpperCase();
    }

    /**
     * 生成查询号码，六位随机数字字符串
     *
     * @return
     */
    public static String generatorInquiryNumber() {
        String randomNumber = String.valueOf((int) ((Math.random() * 9 + 1) * 100000));
        return randomNumber;
    }
}
